﻿
// Function used to call the Silverlight client for Blobs management, or to set values to do so in he existing one.
function openSLClientIfRequired(webUrl, listId, itemId, fieldId, blobId, isUpload) {
    $.ajaxSetup({ cache: false });
    $.getJSON(webUrl + '/_vti_bin/AzureBlobServices/AzureBlobService.svc/IsBlobClientOpened',
        function (isOpened) {
            if (!isOpened) {
                $.post(webUrl + '/_vti_bin/AzureBlobServices/AzureBlobService.svc/CreateAzureSession',
                    function (data, textStatus) { }, "json");

                window.open(webUrl + '/AzureBlobManagerModule/AzureBlobManagerPage.aspx?webUrl='
                    + webUrl,
                    'AzureBlobManager',
                    'width=500,height=250,toolbar=no, location=no, status=no, menubar=no, scrollbars=no, copyhistory=no, resizable=no');
            }
            $.post(webUrl + '/_vti_bin/AzureBlobServices/AzureBlobService.svc/SessionTransferBlob' +
                '?listId=' + listId + '&itemId=' + itemId + '&fieldId=' + fieldId + '&blobId=' + blobId + '&isUpload=' + isUpload,
                function (data, textStatus) { }, "json");
        }
    );
}

function openShareLinkMail(webUrl, listId, itemId, fieldId, blobId) {
    if (confirm("Are you sure you want to share this content?")) {
        $.getJSON(webUrl + '/_vti_bin/AzureBlobServices/AzureBlobService.svc/GetShareLink' +
                '?listId=' + listId + '&itemId=' + itemId + '&fieldId=' + fieldId + '&blobId=' + blobId,
                function (url) {
                    window.location.href = 'mailto:subject=\'Sharing Item \"' + blobId + '\" with you\'&body=\'' + url + '\'';
                });
     }
}